import 'package:flutter/material.dart';
import '../modules/user/controllers/user_controller.dart';
import '../services/screenAdapter.dart';
import 'package:get/get.dart';

class AvatarPopupMenu extends StatelessWidget {
  AvatarPopupMenu({super.key});
  final UserController controller = Get.put(UserController());

  @override
  Widget build(BuildContext context) {
    return PopupMenuButton<String>(
      offset: const Offset(0, 50), // 调整弹出位置
      itemBuilder: (context) => [
        PopupMenuItem(
          onTap: () {
            Get.toNamed('/user');
          },
          value: 'profile',
          height: ScreenAdapter.height(6),
          child: ListTile(leading: Icon(Icons.person), title: Text('个人资料')),
        ),
        PopupMenuItem(
          value: 'logout',
          height: ScreenAdapter.height(10),
          child: ListTile(
            onTap: () {
              controller.logout();
            },
            leading: Icon(Icons.exit_to_app),
            title: Text('退出登录'),
          ),
        ),
      ],
      child: Padding(
        padding: EdgeInsets.all(ScreenAdapter.width(8)),
        child: CircleAvatar(
          radius: ScreenAdapter.width(50),
          backgroundImage: NetworkImage(controller.avatarUrl.value),
        ),
      ),
    );
  }
}
